package com.lilicould.controller;

import com.lilicould.entity.Employee;
import com.lilicould.service.impl.EmployeeServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/update/employee")
public class UpdateEmployeeController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取传入参数
        String employeeId = req.getParameter("employeeId");
        String name = req.getParameter("name");
        String phone = req.getParameter("phone");
        double salary = Double.parseDouble(req.getParameter("salary"));

        // 调用业务逻辑层
        EmployeeServiceImpl employeeService = new EmployeeServiceImpl();
        Employee employee = new Employee(employeeId, name, phone, salary);
        boolean result = employeeService.updateEmployee(employee);
        req.getRequestDispatcher("/employee/info").forward(req,resp);
    }
}
